package com.zj.ssm.service.impl;

import com.zj.ssm.mapper.SubscribeMapper;
import com.zj.ssm.pojo.domain.Subscribe;
import com.zj.ssm.pojo.domain.query.SubscribeQuery;

import com.zj.ssm.result.AjaxResult;
import com.zj.ssm.service.SubscribeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * @author:Coco
 * @date:2022/2/1615:54
 * @version:1.8
 */
@Service
public class SubscribeServiceImpl implements SubscribeService {
    @Autowired
    private SubscribeMapper subscribeMapper;
    @Override
    public AjaxResult updateSubscrilbe(Subscribe subscribe) {
        int i= subscribeMapper.updateSubscrilbe(subscribe);
        if (i>0){
            return AjaxResult.success();
        }
        return AjaxResult.fail();
    }
    @Override
    public AjaxResult getSubscrilbe(Integer id) {
        Subscribe s=subscribeMapper.getSubscribeByID(id);

        return AjaxResult.success(s);
    }



    @Override
    public AjaxResult deleteSubscrilbe(Integer id) {
       int i= subscribeMapper.deleteSubscribe(id);
       if (i>0){
           return AjaxResult.success();
       }
        return AjaxResult.fail();
    }


    @Override
    public AjaxResult querySubscribe(SubscribeQuery query) {

        List<Subscribe>subscribes=subscribeMapper.querySubscribe(query);
        Long aLong=subscribeMapper.querySubscribeTotal(query);
        HashMap<Object, Object> objectObjectHashMap = new HashMap<>();
        objectObjectHashMap.put("currentData",subscribes);
        objectObjectHashMap.put("totalCount",aLong);
        return AjaxResult.success(objectObjectHashMap);


    }

    @Override
    public AjaxResult addSubscribe(Subscribe subscribe) {
        int i= subscribeMapper.addSubscribe(subscribe);
        if (i>1){
            return  AjaxResult.success();

        }
        return AjaxResult.fail();
    }
}


